package org.abacus.http;

public class HttpException extends RuntimeException {
	private String code;

	/**
	 * 
	 */
	private static final long serialVersionUID = -280478499521532699L;

	public HttpException(String code) {
		super();
		this.code = code;
	}

	public HttpException(String message, Throwable cause, String code) {
		super(message, cause);
		this.code = code;
	}

	public HttpException(String message, String code) {
		super(message);
		this.code = code;
	}

	public HttpException(Throwable cause, String code) {
		super(cause);
		this.code = code;
	}

	public String getCode() {
		return code;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		if (null != code) {
			sb.append('[');
			sb.append("code=");
			sb.append(code);
			sb.append(']');
			sb.append(' ');
		}
		String message = super.getMessage();
		if (null != message) {
			sb.append('[');
			sb.append("message=");
			sb.append(message);
			sb.append(']');
			sb.append(' ');
		}
		sb.append("\n\t");
		StackTraceElement[] stackTrace =super.getCause().getStackTrace();
		if (null != stackTrace && stackTrace.length > 0)
			for (StackTraceElement stackTraceElement : stackTrace) {
				sb.append("at ").append(stackTraceElement.getClassName()).append('.');
				sb.append(stackTraceElement.getMethodName()).append('(').append(stackTraceElement.getFileName());
				sb.append(':').append(stackTraceElement.getLineNumber()).append(')').append("\n\t");
			}
		return sb.toString();
	}
}
